<template>
	<form @submit="form.submit($event,success)" :data-action="`/api/servicerCompany/save`">
		
		<view class="father">
			<view class="fixAuto bb middle">
				<view class="w80">
					企业名称
				</view>
				<view class="father">
					<input type="text" name="x.name|企业名称|0~100" v-model="data.name" @input="confirm">
					
				</view>
			</view>
			<view class="abs top whiteBg bd shadow" v-if="list.length" style="top: calc(100% - 1px);">
				<view class="pd" @tap="chooseCompany(item,index)" style="padding-top: 8px!important;padding-bottom: 8px!important;" :class="{bt:index>0}" v-for="( item , index) in list" :key="index">
					{{item.name}}
				</view>
			</view>
		</view>
		
		
		
		<view class="fixAuto bb middle">
			<view class="w80">
				通用名称
			</view>
			<view>
				<input type="text" name="x.simpleName|通用名称|0~100|empty" v-model="data.simpleName">
			</view>
		</view>
		
		<view class="fixAuto bb middle">
			<view class="w80">
				曾用名
			</view>
			<view>
				<input type="text" name="x.nameUsedBefore|曾用名|0~100|empty" v-model="data.nameUsedBefore">
			</view>
		</view>
		
		<view class="fixAuto bb middle" @tap="chooseLocation">
			<view class="w80">
				经纬度
			</view>
			<view :class="{'text-right grey':!data.latitude}">
				{{ data.latitude ? `${data.latitude},${data.longitude}` : '选择位置'}}
				<input type="text" title="经纬度" name="x.latitude|经纬度|0~500" v-model="data.latitude" style="display: none;"></input>
				<input type="text" title="经纬度" name="x.longitude|纬度|0~500" v-model="data.longitude" style="display: none;"></input>
			</view>
			<view class="w30 sIcon-locationFill fz12 main"></view>
		</view>
		
		<view class="fixAuto bb middle">
			<view class="w80">
				企业地址
			</view>
			<view>
				<input type="text" name="x.address|企业地址|0~500" v-model="data.address">
			</view>
		</view>
		
		
		<view class="fixAuto bb middle">
			<view class="w80">
				行业
			</view>
			<view>
				<input type="text" name="x.industry|行业|0~100" v-model="data.industry">
			</view>
		</view>
		
		<view class="fixAuto bb middle">
			<view class="w80">
				联系人
			</view>
			<view>
				<input type="text" name="x.contacts|联系人|0~50" v-model="data.contacts">
			</view>
		</view>
		
		<view class="fixAuto bb middle">
			<view class="w80">
				手机号码
			</view>
			<view>
				<input type="number" name="x.mobile|手机号码|mobile" v-model="data.mobile">
			</view>
		</view>
		
		
		<view class="plr100 pd30">
			<button form-type="submit" class="btn block rds23">
				确认绑定
			</button>
		</view>
		
	</form>
	
</template>

<script>
	import baseFrequency from "../../common/base-frequency.js" ;
	export default {
		data() {
			return {
				data:{
					'latitude' : '' ,
					'longitude' : ''
				},
				list:[] ,
				param:{id:"",type:1} ,
				isNormal : 1 ,
				rangeIsNormal : 1 ,
				typeList : ["异常" ,"正常"]
			}
		},
		
		onLoad(param) {
			this.param = param ;
		},
		
		methods: {
			...baseFrequency,
			success:function(e){
				this.kit.goSuccessBack("绑定成功");
			},
			chooseLocation:function(e){
				uni.chooseLocation({
					latitude: this.data.latitude ,
					longitude : this.data.longitude ,
					type : "gcj02",
					success: (res) => {
						this.data.latitude = res.latitude ;
						this.data.longitude = res.longitude ;
						this.data.address = res.address + res.name ;
					}
				})
			},
			confirm:function(e){
				this.name = e.detail.value ;
				this.delayOnce( e => {
					var data = {name:this.name} ;
					this.kit.get("/api/company/search",data,res => {
						uni.hideLoading();
						this.list = res.list || [] ;
					});
				});
			},
			chooseCompany(item,index){
				this.data = item ;
				this.list = [] ;
			}
		}
	}
</script>

<style>
page{
	background-color: #fff;
}
.fixAuto{
	padding: 30upx 10upx;
}
</style>
